// 解法一：使用对象作为哈希表
function twoSum(nums: number[], target: number): number[] {
  const hash: { [p: number]: number } = {};
  for(let i = 0; i < nums.length; i++) {
    const curr = nums[i];
    if (hash[curr] === undefined) {
      hash[target - curr] = i;
    } else {
      return [hash[curr], i];
    }
  }
  throw new Error('No two numbers can match!');
};